import StudentVerifyModel from "../models/StudentVerifyModel";
import RecordFreeUser from "../models/RecordFreeUser";
import {observable, action, toJS} from "mobx";

class StudentVerifyStore {
    api;
    appStore;
    @observable studentVerifyModel = new StudentVerifyModel();
    @observable RecordFreeUser = new RecordFreeUser();
    @observable isVerify = false;
    @observable isSubmit = false;

    constructor(api, appStore) {
        this.api = api;
        this.appStore = appStore;
    }

    @action getModel() {
        return this.studentVerifyModel;
    }

    @action setModel(studentVerifyModel) {
        this.studentVerifyModel = studentVerifyModel;
    }

    @action setRecordFreeUser(RecordFreeUser){
        this.RecordFreeUser = RecordFreeUser;
    }

    @action getRecordFreeUser(){
        return this.RecordFreeUser;
    }
    // //身份验证
    // @action studentVerify() {
    //     this.appStore.increaseRequest();
    //     return this.api.studentVerify(this.studentVerifyModel.name, this.studentVerifyModel.idCard).then(
    //         action(
    //             data => {
    //                 this.appStore.decreaseRequest();
    //                 if (data) {
    //                     if (data.name == this.studentVerifyModel.name && data.name != null) {
    //                         this.isVerify = true;
    //                         this.studentVerifyModel.studentID = data.studentID;
    //                         this.studentVerifyModel.sex = data.sex;
    //                         this.studentVerifyModel.majorName = data.majorName;
    //                         this.studentVerifyModel.graduateYear = data.graduateYear;
    //                         this.studentVerifyModel.joinYear = data.joinYear;
    //                     }
    //                     else {
    //                         alert("身份验证出错");
    //                     }
    //                     return Promise.resolve();
    //                 } else {
    //                     return Promise.reject();
    //                 }
    //             }
    //         )
    //     );
    // }

    //身份验证
    @action studentVerify(studentVerifyModel) {
        this.appStore.increaseRequest();
        return this.api.studentVerify(studentVerifyModel).then(
            action(data => {
                    this.appStore.decreaseRequest();
                    if (data) {
                        alert("身份验证成功");
                        this.isVerify = true;
                        return Promise.resolve();
                    }
                    else {
                        alert("身份验证出错");
                        return Promise.resolve();
                    }
                }
            )
        );
    }

    //完善信息
    @action addStudent(studentVerifyModel) {
        this.appStore.increaseRequest();
        return this.api.addStudent(studentVerifyModel).then(
            action(data => {
                    this.appStore.decreaseRequest();
                    if (data) {
                        alert("信息完善成功");
                        this.isSubmit = true;
                        return Promise.resolve();
                    } else {
                        alert("信息完善失败");
                        return Promise.reject();
                    }
                }
            )
        );
    }
}

export default StudentVerifyStore;